/**
 * 用户相关 API
 */
import http from '../utils/request'

export interface LoginParams {
  username: string
  password: string
}

export interface UserInfo {
  id: number
  username: string
  email: string
  role: string
  is_active: boolean
  created_at: string
}

export interface LoginResult {
  access_token: string
  user_info: UserInfo
}

// 用户登录
export const login = (params: LoginParams) => {
  return http.post<LoginResult>('/auth/login', params)
}

// 获取用户信息
export const getUserInfo = () => {
  return http.get<UserInfo>('/auth/me')
}

// 刷新 token
export const refreshToken = () => {
  return http.post('/auth/refresh')
}

// 修改密码
export const changePassword = (params: {
  old_password: string
  new_password: string
}) => {
  return http.put('/auth/change-password', params)
}

// 退出登录
export const logout = () => {
  return http.post('/auth/logout')
}